#include <iostream>
#include"head.h"
void menu1(Node* phead)
{ 
 	system("cls");
	while(1)
	{
    	printf("\n数据统计\n");
    	printf("-------------------------------------\n");
		printf("               菜单                  \n");
		printf("1.按性别统计职工人数\n"); 
		printf("2.统计部门对应职工人数\n");
		printf("3.统计人员类别对应职工人数\n");
		printf("4.统计技术等级对应职工人数\n");
		printf("5.统计技术职称对应职工人数\n");
		printf("6.统计文化程度对应职工人数\n");
		printf("7.统计民族对应职工人数\n");
		printf("8.统计籍贯对应职工人数\n");
		printf("0.退出\n"); 
		printf("-------------------------------------\n");
		printf("请选择(0-8)");
		char option[0];
		while(1){

			scanf("%s", &option);
			if(option[0]>='0'&&option[0]<='8'){
				break;
			}
			else{
				printf("输入错误，重新输入0-8\n");
			}
		}

		int choice;
		choice = option[0]-'0';
		system("cls");
		switch (choice)
		{
			case 0:
			{				
				return ;
			}	
	
			case 1:
			{
				int a[1];
				a[0] = 0;
				a[1] = 0;//定义数组，储存男女性人数

				Node* p = phead->next;

				while(p != NULL)
				{
					count_gender(p->data, a);//调用函数，显示结点p数据域
		
					p = p->next;
				}

				printf("女性个数%d\n",a[0]);
	        	printf("男性个数%d\n",a[1]);

				break;
			}
	
			case 2:
			{
				char str[20];
				printf("输入部门：");
				scanf("%s",str);

				int n = 0;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_department(p->data, str, &n);//函数调用

					p = p->next;
				}
				
				printf("%s部门对应职工人数%d", str, n);

				break; 
			}
			
			case 3:
			{
				char str[20];
				printf("输入人员类别：");
				scanf("%s",str);
				
				int n = 0;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_personnel_category(p->data, str, &n);//函数调用
		
					p = p->next;
				}
				
				printf("%s人员类别对应职工人数%d", str, n);

				break; 
			}
			
			case 4:
			{
				int t;
				printf("输入技术等级：");
				scanf("%s",&t);
				
				int n;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_technical_grade(p->data, t, &n);//函数调用

					p = p->next;
				}
				
				printf("%d技术等级对应职工人数%d", t, n);

				break; 
			}
			
			case 5:
			{
				char str[20];
				printf("输入技术职称：");
				scanf("%s",str);
				
				int n;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_technical_titles(p->data, str, &n);//函数调用
		
					p = p->next;
				}

				printf("%s技术职称对应职工人数%d", str, n);

				break; 
			}
			
			case 6:
			{
				char str[20];
				printf("输入文化程度：");
				scanf("%s",str);
				
				int n = 0;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_degree_of_educaation(p->data, str, &n);//函数调用
		
					p = p->next;
				}
				
				printf("%s文化程度对应职工人数%d", str, n);

				break; 
			}
			
			case 7:
			{
				char str[20];
				printf("输入民族：");
				scanf("%s", str);
				
				int n = 0;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_nation(p->data, str, &n);//函数调用
		
					p = p->next;
				}
				
				printf("%s民族对应职工人数%d", str, n);

				break; 
			}
			
			case 8:
			{
				char str[20];
				printf("输入籍贯：");
				scanf("%s",str);
				
				int n = 0;
				Node* p = phead->next;
				while(p != NULL)
				{
					count_native__please(p->data, str, &n);//函数调用
		
					p = p->next;
				}
				
				printf("%s籍贯对应职工人数%d", str, n);

				break; 
			}
			
			default: continue;
		}
		
		system("pause");
	}	
}

void count_gender(void*data, int a[1])
{
	Employee* E = (Employee*)data; 
	
	int n = 0;
	int girl = 0;
	int boy = 0;
	
	n=strcmp(E->gender,"男");
	if(n == 0)
	{
		girl ++;
	}
	else
	{
		boy ++;
	}
    
    a[0] += girl;
    a[1] += boy;
	return;
}

void count_department(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->department,str) == 0)//n初始值为0；每有一个与输入字符相同的数据，则令n自增1，下文的所有统计函数与之同理
	{
		*n = *n+1;
	}

	return;
}

void count_personnel_category(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->personnel_category,str) == 0)
	{
		*n = *n+1;
	}

	return;
}

void count_technical_grade(void*data, int t, int *n)
{
	Employee* E = (Employee*)data; 
	
	if(E->technical_grade == t)
	{
		*n = *n+1;
	}

	return;
}

void count_technical_titles(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->technical_titles,str) == 0)
	{
		*n = *n+1;
	}

	return;
}

void count_degree_of_educaation(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->degree_of_educaation,str) == 0)
	{
		*n = *n+1;
	}

	return;
}

void count_nation(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->nation,str) == 0)
	{
		*n = *n+1;
	}

	return;
}

void count_native__please(void*data, char str[20], int *n)
{
	Employee* E = (Employee*)data; 
	
	if(strcmp(E->native__please,str) == 0)
	{
		*n = *n+1;
	}

	return;
}